package com.liesheng.haylou.view.dialog;


import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.liesheng.haylou.R;
import com.liesheng.haylou.ui.personal.PersonalDataSettingActivity;
import com.liesheng.haylou.utils.ToastUtil;

import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;


/**
 * Date:${DATA}
 * Author ${ZhangZhiQiang}
 * Description
 */
public class NickDialog extends AlertDialog implements View.OnClickListener {
    private EditText etDeviceName;
    private TextView tvClose, tvSave;
    private OnEditInputFinishedListener mListener; //接口

    public interface OnEditInputFinishedListener {
        void editInputFinished(String password);
    }

    public NickDialog(Context context, OnEditInputFinishedListener mListener) {
        super(context);
        this.mListener = mListener;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nick_dialog);
        etDeviceName = findViewById(R.id.et_deviceName);
        tvSave = findViewById(R.id.tv_save);
        tvClose = findViewById(R.id.tv_close);

        tvSave.setOnClickListener(this);
        tvClose.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_save) {
            //确定
            if (mListener != null) {
                String nickName = etDeviceName.getText().toString();
                mListener.editInputFinished(nickName);
            }
            dismiss();
        } else {
            //取消
            dismiss();
        }
    }
}
